# test stack cleanups

var lastSP;
var firstTime 1
var secondTime 0
var preLoopSP;
preLoopSP = sp
loop continue break {
    var v 100
    if (firstTime) {
        lastSP = sp
        firstTime = 0
        secondTime = 1
        continue
    } else {
        if (secondTime) {
            # second time through the loop
            if (lastSP == sp) {
                puts 'ok after continue'
            } else {
                puts 'failed after continue'
            }
            secondTime = 0
        } else {
            # third time through the loop
            if (lastSP == sp) {
                puts 'ok after looping'
            } else {
                puts 'failed after looping'
            }
            break
        }
    }
}

if (preLoopSP == sp) {
    puts 'ok after loop'
} else {
    puts 'failed after loop'
}

if (1) { var a } else { var b }
if (preLoopSP == sp) {
    puts 'ok after "if"'
} else {
    puts 'failed after "if"'
}

if (0) { var a } else { var b }
if (preLoopSP == sp) {
    puts 'ok after "else"'
} else {
    puts 'failed after "else"'
}
